<template>
	<view>
		<button @click="onSetTimeCall()">单次定时器setTimeout</button>
		<button @click="onSetTimeCallxy(userName,password)">带参数setTimeout</button>
		<button @click="onTimeoutClear()" type="warn">取消定时器</button>
		<button @click="onInteral()" type="primary">周期打印</button>
		<button @click="onClearInter()" type="warn" plain="true">取消周期打印</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userName:'wyh',
				password:'0258',
				timeID: null,
				count: 0,
				interalID: null
			}
		},
		methods: {
			onSetTimeCall(){
				console.log("onSetTimeCall-->");
				//setTimeout(callback,ms,ayn[])
				setTimeout(()=>{
					//延时之后要执行的代码
					console.log("我延时3秒才会打印呢");
				},3000)
			},
			onSetTimeCallxy(name,pwd){
				console.log("onSetTimeCallxy--> name:" +name+",pwd:"+pwd);
				// console.log("onSetTimeCallxy--> name:" +this.userName+",pwd:"+this.password")
				setTimeout((x,y)=>{
					console.log("我要延时3秒才会打印");
				},3000)
			},
			onTimeoutclear(){
				console.log("onTimeoutclear--->定时器被我取消了: + this.timeoutID")
				clearTimeout(this.timeoutID);
			},
			onInteral(){
				this.timeoutID = setInterval(()=> {
					this.count++;
					console.log("周期打印 count: ",this.count);
				},1000)
			},
			onclearInter() {
				console.log("onClearInter:",this.interalID);
				clearInterval(this.interalID)
			}
		}
	}
</script>

<style>
button{
	margin: 30rpx;
}
</style>
